﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApi01.Demain
{
    public class DbInitializeHelper
    {

        public static void Initilizer()
        {
            using(var db=new Admin400DbContext())
            {
                db.Database.EnsureCreated();

                var tempBrand = db.Brands.Any();

                if (!tempBrand)
                {
                    var brand = new Brand
                    {
                        BrandName = "Apple",
                        Description = "美国的一个品牌，相当牛币"
                    };

                    db.Brands.Add(brand);

                    

                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName = "Iphone X银色",
                        ShortDesc="简单明了的说",
                        FullDesc="详细的说",
                        BrandId=brand.Id
                    },

                    new Product
                    {
                        ProductName = "Iphone X绿色",
                        ShortDesc="你说",
                        FullDesc="他说",
                        BrandId=brand.Id
                    },

                    });

                    db.SaveChanges();
                }

                
            }

            
        }

    }
}
